package com.ttl.bc.ap.stkrequest;

import org.displaytag.decorator.TableDecorator;


public class BCStkRequestDecorator extends TableDecorator {
	public String getQty1() {						
		BCStkRequestShowBean obj = (BCStkRequestShowBean)getCurrentRowObject();
		float qty = obj.getQty();
				
		return "<label align = 'right'>"+qty+"</label>";

	}
	public String getIttl_status() {
		BCStkRequestShowBean obj = (BCStkRequestShowBean)getCurrentRowObject();
		
		
		if (obj.getIttl_status()!=null && obj.getIttl_status().equals("0")) {
			return "รอเบิก";
		}else if (obj.getIttl_status()!=null && obj.getIttl_status().equals("1")) {
			return "รอซื้อ";
		}else if (obj.getIttl_status()!=null && obj.getIttl_status().equals("2")) {
			return "ซื้อแล้ว";			
		}else if (obj.getIttl_status()!=null && obj.getIttl_status().equals("3")) {
			return "จ่ายแล้ว";
		}else if (obj.getIttl_status()!=null && obj.getIttl_status().equals("4")) {
			return "รับแล้ว";			
		}else if (obj.getIttl_status()!=null && obj.getIttl_status().equals("-1")) {
			return "ยกเลิก";
		}else {
			return "ค่า ittl_status ผิด:"+obj.getIttl_status();
		}
	}	
	public String getMode() {		
		
		BCStkRequestShowBean obj = (BCStkRequestShowBean)getCurrentRowObject();
		String docNo = obj.getDocNo();				
		
		String delete = "";
		String edit = "";
		String print = "<a href=\"/ittl/buyRequest/buyRequest.do?mode=print&docNo="+docNo+"\" target=\"_blank\">Print</a>";
		String receive = "";
		String price = "";
		String po = "";
		if (obj.getIttl_status()!=null && obj.getIttl_status().equals("0")) {
			if (obj.getIttl_status_head()!=null && obj.getIttl_status_head().equals("0")) {
				delete = "<a href=\"/ittl/buyRequest/buyRequest.do?mode=cancel&docNo="+docNo+"\">ลบ</a> | ";
				edit = "<a href=\"/ittl/buyRequest/buyRequest.do?mode=edit&docNo="+docNo+"\">แก้ไข</a> | ";
			}else {
				edit = "item บางอันออก PO แล้ว | ";
			}

		}else if (obj.getIttl_status()!=null && obj.getIttl_status().equals("1")) {
			po = "ออก PO แล้ว  | ";
		}else if (obj.getIttl_status()!=null && obj.getIttl_status().equals("2")) {
//			receive = "<a href=\"/ittl/buyRequest/buyRequest.do?mode=approveShow&docNo="+docNo+"\" >รับของ</a> | ";
			
			String ttl = docNo.substring(0, 2);
			if(ttl.equalsIgnoreCase("F2")) {
				price = "<a href=\"/ittl/buyRequest/buyRequest.do?mode=receiveConfirmShow&docNo="+docNo+"\">รับของ</a>";
				print = "";
			}else {
				po = "ซื้อแล้ว  | ";
//			print = "";
			}
		}else if (obj.getIttl_status()!=null && obj.getIttl_status().equals("3")) {
			price = "<a href=\"/ittl/buyRequest/buyRequest.do?mode=price&docNo="+docNo+"\">ใส่ราคา (ยืนยันรับของ)</a>";			
			print = "";
		}else if (obj.getIttl_status()!=null && obj.getIttl_status().equals("4")) {
			price = "รับแล้ว   |  ";			
//			print = "";			
		}else if (obj.getIttl_status()!=null && obj.getIttl_status().equals("-1")) {			
			delete = "<a href=\"/ittl/buyRequest/buyRequest.do?mode=cancelOfDelete&docNo="+docNo+"\">ยกเลิกการลบ</a>";
			print = "";
		}else {
			delete = "ค่า ittl_status ผิด:"+obj.getIttl_status();
			print = "";			
		}
		
		return "<center>"+price+delete+edit+po+receive+print+"</center>";					
	}
}
